#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/log"
require "#{LKP_SRC}/lib/statistics"

stats = Hash.new { |h, k| h[k] = [] }
unit = nil

while (line = $stdin.gets)
  case line
  when /This system uses (\d+) bytes per array element/
    stats['element_size_byte'] = $1
  when /Array size = (\d+) \(elements\)/
    stats['array_size'] = $1
  when /Function.*Best Rate (.*) Avg time/
    unit = $1.to_s.strip.tr('/', 'p')
  when /(Copy|Scale|Add|Triad)/
    if unit.nil?
      log_error 'can not get unit'
      exit
    end
    stats["#{$1.downcase}_bandwidth_#{unit}"] << line.split[1].to_f
  end
end

stats.each do |k, v|
  if k != 'element_size_byte' && k != 'array_size'
    puts "#{k}: #{v.average.round(2)}"
    puts "#{k}_harmonicMean: #{v.harmonic_mean.round(2)}"
  else
    puts "#{k}: #{v}"
  end
end
